package com.promote.algorithm;

/**
 * @ClassName SumOfSquareNumbers
 * Description 两数平方和
 * @Author LiZiHao
 * Date 2021/6/21 9:53
 * @Version 1.0
 **/
public class SumOfSquareNumbers {

    public static Boolean squareSum(int target) {
        if (target < 0) {
            return false;
        }
        int i = 0;
        int j = (int) Math.sqrt(target);
        while (i < j) {
            int sum = i*i + j*j;
            if (sum == target) {
                return true;
            } else if(sum < target) {
                i++;
            } else {
                j--;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int target = 10;
        final Boolean aBoolean = squareSum(target);

        System.out.println(aBoolean);
    }
}
